package com.lsc.tools;

import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;

public class DomTools {
	
	public static Document loadDomFromString(String s){
		Document d=null;
		try{
		DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
		DocumentBuilder db=dbf.newDocumentBuilder();
		d=db.parse(new InputSource(new StringReader(s)));
		}
		catch (IOException x){
			x.printStackTrace();
		}
		catch (SAXException x){
			x.printStackTrace();
		}
		catch(ParserConfigurationException x){
			x.printStackTrace();
		}
		return d;	
	}

	public static Document loadDomFromStream(InputStream s){
		Document d=null;
		try{
		DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
		DocumentBuilder db=dbf.newDocumentBuilder();
		d=db.parse(new InputSource(s));
		}
		catch (IOException x){
			x.printStackTrace();
		}
		catch (SAXException x){
			x.printStackTrace();
		}
		catch(ParserConfigurationException x){
			x.printStackTrace();
		}
		return d;	
	}

	
}
